using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace Camalon.Drawing.Shapes
{
	[ToolboxItem(true)]
	public class Line : VectorShape
	{
		public Line():base( Rectangle.FromLTRB(100,100,300,100))
		{
			//Initialize your line points
			base.SetPoints(new AnchorPoint[]{ new AnchorPoint( 0,0), new AnchorPoint( 100,100),new AnchorPoint( 200,0)});
		}

		protected override GraphicsPath MakePath(Point[] points, bool closed)
		{
			GraphicsPath path = new GraphicsPath();

			// A line must consist of at least 2 points
			if( points != null && points.Length > 1 )
			{
				//If closed just add a polygon. It makes a closed path.
				if( closed && points.Length > 2) path.AddPolygon(points);
				//Otherwise add lines to path. The path is open.
				else path.AddLines(points);
			}
			else // Failed ? Just add simple rectangle, that our shape does not crash 
				path.AddRectangle( base.Bounds);
				
			// Return the path to the shape-subsystem
			return path;
		}

		protected override bool ValidatePoints(AnchorPoint[] points)
		{
			//Validate the line.  
			if( points == null || points.Length < 2 ) throw new InvalidOperationException("A line must consist of at least two points");
			return true;
		}


	}
}
